//
//  CollectionDetalsViewController.m
//  Leisure
//
//  Created by xalo on 16/7/5.
//  Copyright © 2016年 朱旭东. All rights reserved.
//

#import "CollectionDetalsViewController.h"

@interface CollectionDetalsViewController ()<UIWebViewDelegate>
@property (weak, nonatomic) IBOutlet UIWebView *webView;

@end

@implementation CollectionDetalsViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self.webView  loadRequest:[NSURLRequest requestWithURL:[NSURL  URLWithString:self.html]]];
    
    [self.webView  loadHTMLString:self.html baseURL:nil];
}

#pragma mark -------UIWebViewDelegate

- (void)webViewDidFinishLoad:(UIWebView *)webView{
    NSLog(@"加载完成");
    
    //正则表达式，屏幕自适应
    NSString *js = @"function imgAutoFit() { \
    var imgs = document.getElementsByTagName('img'); \
    for (var i = 0; i < imgs.length; ++i) {\
    var img = imgs[i];   \
    img.style.maxWidth = %f;   \
    } \
    }";
    js = [NSString stringWithFormat:js, [UIScreen mainScreen].bounds.size.width - 20];
    
    [webView stringByEvaluatingJavaScriptFromString:js];
    [webView stringByEvaluatingJavaScriptFromString:@"imgAutoFit()"];
    
}

- (void)webViewDidStartLoad:(UIWebView *)webView{
    NSLog(@"开始加载");
}


@end
